package com.daz.student.lifePlan.action;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.daz.student.lifePlan.pojo.LifePlanPojo;
import com.daz.student.lifePlan.server.ILifePlanSV;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LifePlanAction extends ActionSupport{
	@Autowired
	private ILifePlanSV lifePlanSV;
	
	private String id;
    private String remark;
    private Date createDate;
    private String evaluate;
    private String state;
    private String studentId;
    private String conentText;
    private Date modifyDateLimit;
    
    private String msg;
    private Boolean success;
    
    private List<LifePlanPojo> list; 
    
    public String qryLifePlanByParameter(){
    	Map<String, Object> map = new HashMap<String, Object>();
    	if(id != null){
    		map.put("id", id);
    	}
    	Map<String, Object> session = ActionContext.getContext().getSession();
    	//session.get("studentId")
    	if(studentId != null){
    		map.put("studentId", studentId);
    	}
    	else if(session.get("studentId") != null){
    		map.put("studentId", session.get("studentId"));
    	}
    	try {
			list = lifePlanSV.selectByParameter(map);
			this.setSuccess(true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setSuccess(false);
			this.setMsg("系统错误！");
		}
    	return SUCCESS;
    }
    
    public String addLifePlan(){
    	LifePlanPojo value = new LifePlanPojo();
    	Map<String, Object> session = ActionContext.getContext().getSession();
    	//session.get("studentId")
    	if(session.get("studentId") != null){
    		value.setStudentId((String)session.get("studentId"));
    	}else{
    		this.setSuccess(false);
			this.setMsg("学生号获取失败！");
    		return SUCCESS;
    	}
    	if(remark != null)
    		value.setRemark(remark);
    	Date date  = new Date();
    	value.setCreateDate(date);
    	Calendar calendar = new GregorianCalendar(); 
	    calendar.setTime(date); 
	    calendar.add(calendar.DATE,7);//把日期往后增加7天.
	    date=calendar.getTime();   //这个时间就是日期往后推一天的结果 
		value.setModifyDateLimit(date);
    	if(conentText != null){
    		value.setConentText(conentText);
    	}
    	value.setState("0");
    	try {
			lifePlanSV.insertSelective(value);
			this.setSuccess(true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setSuccess(false);
			this.setMsg("系统错误！");
		}
    	return SUCCESS;
    }
    
    public String updateLifePlanByParam(){
    	LifePlanPojo value = new LifePlanPojo();
    	Map<String, Object> session = ActionContext.getContext().getSession();
    	//session.get("studentId")
    	if(session.get("studentId") != null){
    		value.setStudentId((String)session.get("studentId"));
    	}else{
    		value.setStudentId(studentId);
    		/*this.setSuccess(false);
			this.setMsg("学生号获取失败！");
    		return SUCCESS;*/
    	}
    	if(remark != null)
    		value.setRemark(remark);
    
    	if(conentText != null){
    		value.setConentText(conentText);
    	}
    	if(state != null)
    		value.setState(state);
    	if(id != null)
    		value.setId(id);
    	if(evaluate != null)
    		value.setEvaluate(evaluate);
    	value.setDoneDate(new Date());
    	try {
			lifePlanSV.updateByPrimaryKeySelective(value);
			this.setSuccess(true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			this.setSuccess(false);
			this.setMsg("系统错误！");
		}
    	return SUCCESS;
    }
    
	public Date getModifyDateLimit() {
		return modifyDateLimit;
	}

	public void setModifyDateLimit(Date modifyDateLimit) {
		this.modifyDateLimit = modifyDateLimit;
	}

	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public Boolean getSuccess() {
		return success;
	}
	public void setSuccess(Boolean success) {
		this.success = success;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public String getEvaluate() {
		return evaluate;
	}
	public void setEvaluate(String evaluate) {
		this.evaluate = evaluate;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getStudentId() {
		return studentId;
	}
	public void setStudentId(String studentId) {
		this.studentId = studentId;
	}
	public String getConentText() {
		return conentText;
	}
	public void setConentText(String conentText) {
		this.conentText = conentText;
	}

	public List<LifePlanPojo> getList() {
		return list;
	}

	public void setList(List<LifePlanPojo> list) {
		this.list = list;
	}
    
    
}
